import { readUriToTextAndExplode } from "../readFileToText/openTextFile";
import { PredefinedServerData } from "../classes/PredefinedServerData";
import { ConnectionData } from "../classes/ConnectionData";
import { MenuController } from "../tauriUtils/MenuController";

export async function loadServerFile(uri: string) {
    const reg = new RegExp('(?<addr>\\S*)\\s(?<name>.*)');
    const lines = await readUriToTextAndExplode(uri);
    for (const line of lines) {
        const match = reg.exec(line);
        if (match != null && match.groups != undefined) {
            const g = match.groups;
            const server = new PredefinedServerData();
            server.addr = g.addr;
            server.name = g.name;
            ConnectionData.availablePredefinedServer.push(server);
        }
    }
    await MenuController.refresh();
    console.log('loadServerFile', ConnectionData.availablePredefinedServer);
}